{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from time import time\n",
    "from datetime import datetime\n",
    "import pandas as pd\n",
    "import tushare as ts\n",
    "import tushare as ts\n",
    "from datetime import time\n",
    "from datetime import date, datetime, timedelta\n",
    "from vnpy.trader.constant import Status, Interval, Direction, Exchange, Interval\n",
    "from vnpy.trader.optimize import OptimizationSetting\n",
    "from vnpy_ctastrategy.backtesting import BacktestingEngine\n",
    "from vnpy.trader.setting import SETTINGS\n",
    "import vnpy_tushare\n",
    "from datetime import datetime\n",
    "from vnpy_tushare.tushare_datafeed import TushareDatafeed\n",
    "from vnpy.trader.object import HistoryRequest\n",
    "\n",
    "from vnpy_ctastrategy import (\n",
    "    CtaTemplate,\n",
    "    StopOrder,\n",
    "    TickData,\n",
    "    BarData,\n",
    "    TradeData,\n",
    "    OrderData,\n",
    "    BarGenerator,\n",
    "    ArrayManager,\n",
    ")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 宏观数据获取"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "token=\"600713cc777ee2505142620a527eebe2c27a973b5fe89fce9fe8f07f\"\n",
    "pro = ts.pro_api(token=token)\n",
    "\n",
    "current_q = f\"{datetime.now().year}Q{(datetime.now().month)//3 +1}\"\n",
    "gdp_df = pro.cn_gdp(end_q=current_q, fields='quarter,gdp_yoy')\n",
    "gdp_df.to_csv(\".\\\\data\\\\gdp_data.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "today = datetime.now().strftime(\"%Y%m\")\n",
    "cpi_df = pro.cn_cpi(end_m=today, fields='month,nt_yoy')\n",
    "cpi_df.to_csv(\".\\\\data\\\\cpi_data.csv\", index=True)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "cpi_path = '.\\\\data\\\\cpi_data.csv'\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 选择沪深300ETF作为交易对象（因为其本身就反应了股票市场的情况）\n",
    "engine = BacktestingEngine()\n",
    "engine.set_parameters(\n",
    "    vt_symbol=\"510300.SSE\",\n",
    "    interval=\"d\",\n",
    "    start=datetime(2024, 1, 1),\n",
    "    end=datetime(2024, 12, 30),\n",
    "    rate=0.3/10000,\n",
    "    slippage=0.003,\n",
    "    size=100,   # 每手数量\n",
    "    pricetick=0.1,\n",
    "    capital=1_000_000,    # 初始资金\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "SETTINGS['datafeed.username'] = \"token\"\n",
    "SETTINGS['datafeed.password'] = \"600713cc777ee2505142620a527eebe2c27a973b5fe89fce9fe8f07f\"\n",
    "\n",
    "tsengine = TushareDatafeed()\n",
    "req = HistoryRequest(engine.vt_symbol.split('.')[0], Exchange.SSE, datetime(2024, 1, 1, 0, 0, 0), datetime(2024, 12, 31, 23, 59, 59), Interval.DAILY)\n",
    "data = tsengine.query_bar_history(req)\n",
    "engine.history_data.extend(data)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### CompositeStrategy是上节课的策略 MacroMarketStrategy是在CompositeStrategy的基础上考虑了宏观经济形势的策略"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "class CompositeStrategy(CtaTemplate):\n",
    "    \"\"\"三因子复合策略（双均线+布林带+ATR RSI）\"\"\"\n",
    "    author = \"Youpeng Hu\"\n",
    "\n",
    "    # === 参数设置 ===\n",
    "    fast_window = 5        # 快速均线周期\n",
    "    slow_window = 10       # 慢速均线周期\n",
    "    boll_window = 20       # 布林带窗口\n",
    "    boll_dev = 1.8         # 标准差倍数\n",
    "    rsi_window = 14        # RSI周期\n",
    "    rsi_entry = 30         # RSI入场阈值\n",
    "    atr_window = 14        # ATR周期\n",
    "    atr_ma_window = 10     # ATR均线窗口\n",
    "    stop_multiplier = 3.0  # 止损系数\n",
    "    max_pos = 1000         # 最大持仓\n",
    "    risk_ratio = 0.02      # 风险比例\n",
    "    dividend_days_before = 2  # 分红前N天清仓\n",
    "\n",
    "    parameters = [\n",
    "        \"fast_window\", \"slow_window\",\n",
    "        \"boll_window\", \"boll_dev\",\n",
    "        \"rsi_window\", \"rsi_entry\",\n",
    "        \"atr_window\", \"atr_ma_window\",\n",
    "        \"stop_multiplier\", \"max_pos\", \"risk_ratio\",\n",
    "        \"dividend_days_before\"\n",
    "    ]\n",
    "\n",
    "    variables = [\n",
    "        \"fast_ma\", \"slow_ma\",\n",
    "        \"boll_up\", \"boll_mid\", \"boll_down\",\n",
    "        \"rsi_value\", \"atr_value\", \"atr_ma\",\n",
    "        \"intra_trade_low\"\n",
    "    ]\n",
    "\n",
    "    def __init__(self, cta_engine, strategy_name, vt_symbol, setting):\n",
    "        super().__init__(cta_engine, strategy_name, vt_symbol, setting)\n",
    "        \n",
    "        # K线生成器\n",
    "        self.bg = BarGenerator(\n",
    "            self.on_bar,\n",
    "            interval=Interval.DAILY,\n",
    "            daily_end=time(15, 0)\n",
    "        )\n",
    "        self.am = ArrayManager(size=100)\n",
    "        self.last_trade_date = None\n",
    "        self.pro = ts.pro_api(token='600713cc777ee2505142620a527eebe2c27a973b5fe89fce9fe8f07f')\n",
    "        # 存储分红日期数据\n",
    "        self.dividend_dates = []\n",
    "        self.load_dividend_data()  # 初始化时加载数据\n",
    "\n",
    "    def load_dividend_data(self):\n",
    "        \"\"\"根据动态vt_symbol加载分红数据\"\"\"\n",
    "        # 1. 解析vt_symbol为ts_code\n",
    "        try:\n",
    "            symbol_part, exchange_suffix = self.vt_symbol.split(\".\")\n",
    "        except ValueError:\n",
    "            self.write_log(f\"无效vt_symbol格式：{self.vt_symbol}，应为'代码.交易所'格式（如600848.SH）\")\n",
    "            return\n",
    "        \n",
    "        # 2. 转换为Tushare需要的ts_code格式\n",
    "        ts_code = f\"{symbol_part}.{exchange_suffix}\"\n",
    "        \n",
    "        # 3. 调用Tushare接口\n",
    "        try:\n",
    "            raw_df = self.pro.dividend(\n",
    "                ts_code=ts_code, \n",
    "                fields=\"ex_date,div_proc,stk_div\"\n",
    "            )\n",
    "        except Exception as e:\n",
    "            self.write_log(f\"股票{ts_code}分红数据获取失败：{str(e)}\")\n",
    "            return\n",
    "\n",
    "        # 4. 处理返回的DataFrame\n",
    "        self.dividend_dates = []\n",
    "        if not raw_df.empty:\n",
    "            for _, row in raw_df.iterrows():\n",
    "                item = row.to_dict()\n",
    "\n",
    "    def is_near_dividend(self, bar_date: date) -> bool:\n",
    "        \"\"\"判断是否在分红敏感期\"\"\"\n",
    "        for ex_date in self.dividend_dates:\n",
    "            # 计算关键日期\n",
    "            record_date = ex_date - timedelta(days=1)   \n",
    "            danger_start = record_date - timedelta(days=self.dividend_days_before)\n",
    "            \n",
    "            if danger_start <= bar_date <= ex_date:\n",
    "                return True\n",
    "        return False\n",
    "\n",
    "    def on_init(self):\n",
    "        \"\"\"策略初始化\"\"\"\n",
    "        self.load_bar(30)  # 加载30根K线\n",
    "        self.write_log(\"策略初始化完成\")\n",
    "\n",
    "    def on_bar(self, bar: BarData):\n",
    "        \"\"\"核心交易逻辑\"\"\"\n",
    "        # 数据有效性校验\n",
    "        if bar.close_price <= 0 or bar.datetime.date() == self.last_trade_date:\n",
    "            return\n",
    "            \n",
    "        self.am.update_bar(bar)\n",
    "        if not self.am.inited:\n",
    "            return\n",
    "\n",
    "        # 转换K线时间为date对象\n",
    "        bar_date = bar.datetime.date()\n",
    "        \n",
    "        # 检查是否在分红敏感期\n",
    "        if self.is_near_dividend(bar_date):\n",
    "            self.write_log(f\"进入分红敏感期，当前日期{bar_date}\")\n",
    "            \n",
    "            # 强制清仓\n",
    "            if self.pos != 0:\n",
    "                self.sell(bar.close_price * 0.995, abs(self.pos))\n",
    "                self.cancel_all()\n",
    "                \n",
    "            # 禁止新开仓\n",
    "            return\n",
    "        # === 指标计算 ===\n",
    "        self._calculate_indicators(bar)\n",
    "        \n",
    "        # === 交易信号 ===\n",
    "        # volume_condition是当前成交量大于过去5日均量的1.2倍。\n",
    "\t\t# l1_signal是快速均线大于慢速，且收盘价高于布林中轨；\n",
    "\t\t# l2_signal是ATR值大于其均线，且收盘价高于布林上轨；\n",
    "\t\t# l3_signal是RSI小于入场阈值，但当前值大于过去5个的最小值。\n",
    "\n",
    "        volume_condition = bar.volume > self.am.volume[-5:].mean() * 1.2\n",
    "        l1_signal = (self.fast_ma > self.slow_ma) and (bar.close_price > self.boll_mid)\n",
    "        l2_signal = (self.atr_value > self.atr_ma) and (bar.close_price > self.boll_up)\n",
    "        l3_signal = (self.rsi_value < self.rsi_entry) and (self.rsi_value > self.rsi_array[-5:].min())\n",
    "        # === 交易执行 ===\n",
    "        self.cancel_all()\n",
    "        self.add_risk_control()  # 激活风控模块\n",
    "        \n",
    "        # 修正后的开仓条件\n",
    "        if ((l1_signal and l2_signal) or (l2_signal and l3_signal)) \\\n",
    "           and self.pos == 0 \\\n",
    "           and volume_condition:\n",
    "            \n",
    "            size = self._calculate_position_size(bar)\n",
    "            price = min(bar.close_price * 1.005, bar.high_price * 0.995)\n",
    "            self.buy(price, size)\n",
    "            self.intra_trade_low = bar.low_price\n",
    "            self.last_trade_date = bar.datetime.date()\n",
    "\n",
    "        # 持仓管理\n",
    "        elif self.pos > 0:\n",
    "            self._manage_position(bar)\n",
    "\n",
    "    def _calculate_indicators(self, bar):\n",
    "        \"\"\"集中计算技术指标\"\"\"\n",
    "        self.fast_ma = self.am.sma(self.fast_window)\n",
    "        self.slow_ma = self.am.sma(self.slow_window)\n",
    "        self.boll_up, self.boll_down = self.am.boll(self.boll_window, self.boll_dev)\n",
    "        self.boll_mid = self.am.sma(self.boll_window)\n",
    "        self.rsi_value = self.am.rsi(self.rsi_window)\n",
    "        atr_array = self.am.atr(self.atr_window, array=True)\n",
    "        self.atr_value = atr_array[-1]\n",
    "        self.atr_ma = atr_array[-self.atr_ma_window:].mean()\n",
    "        self.rsi_array = self.am.rsi(self.rsi_window, array=True)\n",
    "        self.rsi_value = self.rsi_array[-1]  # 当前RSI值\n",
    "\n",
    "    def _manage_position(self, bar: BarData):\n",
    "        \"\"\"持仓管理\"\"\"\n",
    "        # 更新intra_trade_low为当前最低价和之前的intra_trade_low中的较小值，\n",
    "        # 计算止损价和止盈价（布林中轨的1.05倍）。如果当前价格跌破止损或超过止盈，就平仓。\n",
    "        self.intra_trade_low = min(self.intra_trade_low, bar.low_price)\n",
    "        stop_price = self._calculate_stop_price(bar)\n",
    "        take_profit = self.boll_mid * 1.05\n",
    "\n",
    "        if bar.close_price < stop_price or bar.close_price > take_profit:\n",
    "            self.sell(bar.close_price, abs(self.pos))\n",
    "            self.last_trade_date = bar.datetime.date()  # 平仓日期记录\n",
    "\n",
    "    def _calculate_stop_price(self, bar) -> float:\n",
    "        \"\"\"复合止损策略\"\"\"\n",
    "        # 结合ATR止损（最近低点减去ATR乘以系数）和趋势止损（慢速均线的97%），取两者中的较大值作为止损价\n",
    "        atr_stop = self.intra_trade_low - self.atr_value * self.stop_multiplier\n",
    "        trend_stop = self.slow_ma * 0.97\n",
    "        return max(atr_stop, trend_stop)\n",
    "\n",
    "    def _calculate_position_size(self, bar) -> int:\n",
    "        \"\"\"基于波动率的仓位管理\"\"\"\n",
    "        # 仓位计算_calculate_position_size是根据风险比例计算风险金额，然后除以ATR的两倍，再与最大持仓比较取小值\n",
    "        risk_amount = self.cta_engine.capital * self.risk_ratio\n",
    "        return min(int(risk_amount / (self.atr_value * 2)), self.max_pos)\n",
    "\n",
    "    def add_risk_control(self):\n",
    "        \"\"\"增强风控模块\"\"\"\n",
    "        # 持仓量风控\n",
    "        # 检查持仓是否超过最大持仓的80%，如果是就停止策略\n",
    "        if self.pos >= self.max_pos * 0.8:\n",
    "            self.write_log(\"触发单品种持仓限制\")\n",
    "            self.on_stop()\n",
    "        \n",
    "        # 周回撤控制\n",
    "        \"\"\"\n",
    "        if hasattr(self.cta_engine, 'get_weekly_drawdown'):\n",
    "            if self.cta_engine.get_weekly_drawdown() > 0.10:\n",
    "                self.sell(bar.close_price, abs(self.pos))\n",
    "                self.write_log(\"触发周最大回撤限制\")\n",
    "        \"\"\"\n",
    "\t\t\t\t\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "class MacroMarketStrategy(CtaTemplate):\n",
    "    \"\"\"宏观经济环境+股市环境三因子复合策略（双均线+布林带+ATR RSI）\"\"\"\n",
    "    author = \"Youpeng Hu\"\n",
    "\n",
    "    # === 参数设置 ===\n",
    "    fast_window = 5        # 快速均线周期\n",
    "    slow_window = 10       # 慢速均线周期\n",
    "    boll_window = 20       # 布林带窗口\n",
    "    boll_dev = 1.8         # 标准差倍数\n",
    "    rsi_window = 14        # RSI周期\n",
    "    rsi_entry = 30         # RSI入场阈值\n",
    "    atr_window = 14        # ATR周期\n",
    "    atr_ma_window = 10     # ATR均线窗口\n",
    "    stop_multiplier = 3.0  # 止损系数\n",
    "    max_pos = 1000         # 最大持仓\n",
    "    risk_ratio = 0.02      # 风险比例\n",
    "    dividend_days_before = 2  # 分红前N天清仓\n",
    "    cpi_threshold = 0.5  # CPI阈值\n",
    "\n",
    "    # 数据存储\n",
    "    cpi_data = {}\n",
    "    last_cpi_month = None\n",
    "    current_month = None\n",
    "\n",
    "    parameters = [\n",
    "        \"fast_window\", \"slow_window\",\n",
    "        \"boll_window\", \"boll_dev\",\n",
    "        \"rsi_window\", \"rsi_entry\",\n",
    "        \"atr_window\", \"atr_ma_window\",\n",
    "        \"stop_multiplier\", \"max_pos\", \"risk_ratio\",\n",
    "        \"dividend_days_before\", \"cpi_threshold\"\n",
    "    ]\n",
    "\n",
    "    variables = [\n",
    "        \"fast_ma\", \"slow_ma\",\n",
    "        \"boll_up\", \"boll_mid\", \"boll_down\",\n",
    "        \"rsi_value\", \"atr_value\", \"atr_ma\",\n",
    "        \"intra_trade_low\", \"cpi_condition_met\"\n",
    "    ]\n",
    "\n",
    "    def __init__(self, cta_engine, strategy_name, vt_symbol, setting):\n",
    "        super().__init__(cta_engine, strategy_name, vt_symbol, setting)\n",
    "        \n",
    "        # K线生成器\n",
    "        self.bg = BarGenerator(\n",
    "            self.on_bar,\n",
    "            interval=Interval.DAILY,\n",
    "            daily_end=time(15, 0)\n",
    "        )\n",
    "        self.am = ArrayManager(size=100)\n",
    "        self.last_trade_date = None\n",
    "        self.pro = ts.pro_api(token='600713cc777ee2505142620a527eebe2c27a973b5fe89fce9fe8f07f')\n",
    "        # 存储分红日期数据\n",
    "        self.dividend_dates = []\n",
    "        self.load_dividend_data()  # 初始化时加载数据\n",
    "        self.load_cpi_data()  # 加载CPI数据\n",
    "\n",
    "    def load_dividend_data(self):\n",
    "        \"\"\"根据动态vt_symbol加载分红数据\"\"\"\n",
    "        # 1. 解析vt_symbol为ts_code\n",
    "        try:\n",
    "            symbol_part, exchange_suffix = self.vt_symbol.split(\".\")\n",
    "        except ValueError:\n",
    "            self.write_log(f\"无效vt_symbol格式：{self.vt_symbol}，应为'代码.交易所'格式（如600848.SH）\")\n",
    "            return\n",
    "        \n",
    "        # 2. 转换为Tushare需要的ts_code格式\n",
    "        ts_code = f\"{symbol_part}.{exchange_suffix}\"\n",
    "        \n",
    "        # 3. 调用Tushare接口\n",
    "        try:\n",
    "            raw_df = self.pro.dividend(\n",
    "                ts_code=ts_code, \n",
    "                fields=\"ex_date,div_proc,stk_div\"\n",
    "            )\n",
    "        except Exception as e:\n",
    "            self.write_log(f\"股票{ts_code}分红数据获取失败：{str(e)}\")\n",
    "            return\n",
    "\n",
    "        # 4. 处理返回的DataFrame\n",
    "        self.dividend_dates = []\n",
    "        if not raw_df.empty:\n",
    "            for _, row in raw_df.iterrows():\n",
    "                item = row.to_dict()\n",
    "\n",
    "    def is_near_dividend(self, bar_date: date) -> bool:\n",
    "        \"\"\"判断是否在分红敏感期\"\"\"\n",
    "        for ex_date in self.dividend_dates:\n",
    "            # 计算关键日期\n",
    "            record_date = ex_date - timedelta(days=1)   \n",
    "            danger_start = record_date - timedelta(days=self.dividend_days_before)\n",
    "            \n",
    "            if danger_start <= bar_date <= ex_date:\n",
    "                return True\n",
    "        return False\n",
    "\n",
    "    def load_cpi_data(self):\n",
    "        \"\"\"加载本地CPI数据\"\"\"\n",
    "        df = pd.read_csv(cpi_path, dtype={\"month\": str})\n",
    "        self.cpi_data = df.set_index(\"month\").to_dict()[\"nt_yoy\"]\n",
    "        # print(df.head())\n",
    "\n",
    "    def on_init(self):\n",
    "        \"\"\"策略初始化\"\"\"\n",
    "        self.load_bar(30)  # 加载30根K线\n",
    "        self.write_log(\"策略初始化完成\")\n",
    "\n",
    "    def on_bar(self, bar: BarData):\n",
    "        \"\"\"核心交易逻辑\"\"\"\n",
    "        # 数据有效性校验\n",
    "        if bar.close_price <= 0 or bar.datetime.date() == self.last_trade_date:\n",
    "            return\n",
    "            \n",
    "        self.am.update_bar(bar)\n",
    "        if not self.am.inited:\n",
    "            return\n",
    "\n",
    "        # 转换K线时间为date对象\n",
    "        bar_date = bar.datetime.date()\n",
    "        \n",
    "        # 检查是否在分红敏感期\n",
    "        if self.is_near_dividend(bar_date):\n",
    "            self.write_log(f\"进入分红敏感期，当前日期{bar_date}\")\n",
    "            \n",
    "            # 强制清仓\n",
    "            if self.pos != 0:\n",
    "                self.sell(bar.close_price * 0.995, abs(self.pos))\n",
    "                self.cancel_all()\n",
    "                \n",
    "            # 禁止新开仓\n",
    "            return\n",
    "        # === 指标计算 ===\n",
    "        self._calculate_indicators(bar)\n",
    "        \n",
    "        # === 交易信号 ===\n",
    "        # volume_condition是当前成交量大于过去5日均量的1.2倍。\n",
    "\t\t# l1_signal是快速均线大于慢速，且收盘价高于布林中轨；\n",
    "\t\t# l2_signal是ATR值大于其均线，且收盘价高于布林上轨；\n",
    "\t\t# l3_signal是RSI小于入场阈值，但当前值大于过去5个的最小值。\n",
    "        \n",
    "        # 检查CPI条件\n",
    "        current_date = bar.datetime.strftime(\"%Y%m\")\n",
    "        self.cpi_condition_met = False\n",
    "\n",
    "        if current_date in self.cpi_data:\n",
    "            last_month = (datetime.strptime(current_date, \"%Y%m\") - pd.DateOffset(months=1)).strftime(\"%Y%m\")\n",
    "            # print(last_month)\n",
    "            if last_month in self.cpi_data:\n",
    "                self.cpi_condition_met = self.cpi_data[last_month] < self.cpi_threshold\n",
    "\n",
    "        volume_condition = bar.volume > self.am.volume[-5:].mean() * 1.2\n",
    "        l1_signal = (self.fast_ma > self.slow_ma) and (bar.close_price > self.boll_mid)\n",
    "        l2_signal = (self.atr_value > self.atr_ma) and (bar.close_price > self.boll_up)\n",
    "        l3_signal = (self.rsi_value < self.rsi_entry) and (self.rsi_value > self.rsi_array[-5:].min())\n",
    "        \n",
    "        # print(l1_signal, l2_signal, l3_signal, self.cpi_condition_met)\n",
    "        \n",
    "        # === 交易执行 ===\n",
    "        self.cancel_all()\n",
    "        self.add_risk_control()  # 激活风控模块\n",
    "        \n",
    "        # 修正后的开仓条件\n",
    "        if ((l1_signal and l2_signal) or (l2_signal and l3_signal)) \\\n",
    "           and self.pos == 0 \\\n",
    "           and volume_condition \\\n",
    "           and self.cpi_condition_met:\n",
    "            \n",
    "            size = self._calculate_position_size(bar)\n",
    "            price = min(bar.close_price * 1.005, bar.high_price * 0.995)\n",
    "            self.buy(price, size)\n",
    "            self.intra_trade_low = bar.low_price\n",
    "            self.last_trade_date = bar.datetime.date()\n",
    "\n",
    "        # 持仓管理\n",
    "        elif self.pos > 0:\n",
    "            self._manage_position(bar)\n",
    "\n",
    "    def _calculate_indicators(self, bar):\n",
    "        \"\"\"集中计算技术指标\"\"\"\n",
    "        self.fast_ma = self.am.sma(self.fast_window)\n",
    "        self.slow_ma = self.am.sma(self.slow_window)\n",
    "        self.boll_up, self.boll_down = self.am.boll(self.boll_window, self.boll_dev)\n",
    "        self.boll_mid = self.am.sma(self.boll_window)\n",
    "        self.rsi_value = self.am.rsi(self.rsi_window)\n",
    "        atr_array = self.am.atr(self.atr_window, array=True)\n",
    "        self.atr_value = atr_array[-1]\n",
    "        self.atr_ma = atr_array[-self.atr_ma_window:].mean()\n",
    "        self.rsi_array = self.am.rsi(self.rsi_window, array=True)\n",
    "        self.rsi_value = self.rsi_array[-1]  # 当前RSI值\n",
    "\n",
    "    def _manage_position(self, bar: BarData):\n",
    "        \"\"\"持仓管理\"\"\"\n",
    "        # 更新intra_trade_low为当前最低价和之前的intra_trade_low中的较小值，\n",
    "        # 计算止损价和止盈价（布林中轨的1.05倍）。如果当前价格跌破止损或超过止盈，或者此时cpi大于阈值，经济环境不行时就平仓。\n",
    "        self.intra_trade_low = min(self.intra_trade_low, bar.low_price)\n",
    "        stop_price = self._calculate_stop_price(bar)\n",
    "        take_profit = self.boll_mid * 1.05\n",
    "\n",
    "        if bar.close_price < stop_price or bar.close_price > take_profit or not self.cpi_condition_met:\n",
    "            self.sell(bar.close_price, abs(self.pos))\n",
    "            self.last_trade_date = bar.datetime.date()  # 平仓日期记录\n",
    "\n",
    "    def _calculate_stop_price(self, bar) -> float:\n",
    "        \"\"\"复合止损策略\"\"\"\n",
    "        # 结合ATR止损（最近低点减去ATR乘以系数）和趋势止损（慢速均线的97%），取两者中的较大值作为止损价\n",
    "        atr_stop = self.intra_trade_low - self.atr_value * self.stop_multiplier\n",
    "        trend_stop = self.slow_ma * 0.97\n",
    "        return max(atr_stop, trend_stop)\n",
    "\n",
    "    def _calculate_position_size(self, bar) -> int:\n",
    "        \"\"\"基于波动率的仓位管理\"\"\"\n",
    "        # 仓位计算_calculate_position_size是根据风险比例计算风险金额，然后除以ATR的两倍，再与最大持仓比较取小值\n",
    "        risk_amount = self.cta_engine.capital * self.risk_ratio\n",
    "        return min(int(risk_amount / (self.atr_value * 2)), self.max_pos)\n",
    "\n",
    "    def add_risk_control(self):\n",
    "        \"\"\"增强风控模块\"\"\"\n",
    "        # 持仓量风控\n",
    "        # 检查持仓是否超过最大持仓的80%，如果是就停止策略\n",
    "        if self.pos >= self.max_pos * 0.8:\n",
    "            self.write_log(\"触发单品种持仓限制\")\n",
    "            self.on_stop()\n",
    "        \n",
    "        # 周回撤控制\n",
    "        \"\"\"\n",
    "        if hasattr(self.cta_engine, 'get_weekly_drawdown'):\n",
    "            if self.cta_engine.get_weekly_drawdown() > 0.10:\n",
    "                self.sell(bar.close_price, abs(self.pos))\n",
    "                self.write_log(\"触发周最大回撤限制\")\n",
    "        \"\"\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2025-03-16 18:37:08.580102\t策略初始化完成\n",
      "2025-03-16 18:37:08.580102\t开始回放历史数据\n",
      "2025-03-16 18:37:08.581088\t回放进度：= [0%]\n",
      "2025-03-16 18:37:08.581088\t回放进度：== [10%]\n",
      "2025-03-16 18:37:08.581088\t回放进度：=== [20%]\n",
      "2025-03-16 18:37:08.582097\t回放进度：==== [30%]\n",
      "2025-03-16 18:37:08.582097\t回放进度：===== [40%]\n",
      "2025-03-16 18:37:08.583084\t回放进度：====== [50%]\n",
      "2025-03-16 18:37:08.584090\t回放进度：======= [60%]\n",
      "2025-03-16 18:37:08.585034\t回放进度：======== [70%]\n",
      "2025-03-16 18:37:08.586034\t回放进度：========= [80%]\n",
      "2025-03-16 18:37:08.587033\t回放进度：========== [90%]\n",
      "2025-03-16 18:37:08.587033\t回放进度：=========== [100%]\n",
      "2025-03-16 18:37:08.587033\t历史数据回放结束\n",
      "2025-03-16 18:37:08.587033\t开始计算逐日盯市盈亏\n",
      "2025-03-16 18:37:08.589023\t逐日盯市盈亏计算完成\n",
      "2025-03-16 18:37:08.589023\t开始计算策略统计指标\n",
      "2025-03-16 18:37:08.593064\t------------------------------\n",
      "2025-03-16 18:37:08.593064\t首个交易日：\t2024-01-02\n",
      "2025-03-16 18:37:08.593064\t最后交易日：\t2024-12-31\n",
      "2025-03-16 18:37:08.593064\t总交易日：\t242\n",
      "2025-03-16 18:37:08.593064\t盈利交易日：\t22\n",
      "2025-03-16 18:37:08.593064\t亏损交易日：\t27\n",
      "2025-03-16 18:37:08.593064\t起始资金：\t1,000,000.00\n",
      "2025-03-16 18:37:08.594009\t结束资金：\t895,114.98\n",
      "2025-03-16 18:37:08.594009\t总收益率：\t-10.49%\n",
      "2025-03-16 18:37:08.594009\t年化收益：\t-10.40%\n",
      "2025-03-16 18:37:08.594009\t最大回撤: \t-129,193.40\n",
      "2025-03-16 18:37:08.594009\t百分比最大回撤: -12.76%\n",
      "2025-03-16 18:37:08.594009\t最大回撤天数: \t82\n",
      "2025-03-16 18:37:08.594009\t总盈亏：\t-104,885.02\n",
      "2025-03-16 18:37:08.594009\t总手续费：\t185.02\n",
      "2025-03-16 18:37:08.594009\t总滑点：\t4,800.00\n",
      "2025-03-16 18:37:08.594009\t总成交金额：\t6,167,300.00\n",
      "2025-03-16 18:37:08.594009\t总成交笔数：\t12\n",
      "2025-03-16 18:37:08.594009\t日均盈亏：\t-433.41\n",
      "2025-03-16 18:37:08.594009\t日均手续费：\t0.76\n",
      "2025-03-16 18:37:08.594009\t日均滑点：\t19.83\n",
      "2025-03-16 18:37:08.594009\t日均成交金额：\t25,484.71\n",
      "2025-03-16 18:37:08.594009\t日均成交笔数：\t0.049586776859504134\n",
      "2025-03-16 18:37:08.594009\t日均收益率：\t-0.05%\n",
      "2025-03-16 18:37:08.594009\t收益标准差：\t0.80%\n",
      "2025-03-16 18:37:08.594009\tSharpe Ratio：\t-0.89\n",
      "2025-03-16 18:37:08.594009\tEWM Sharpe：\t-0.94\n",
      "2025-03-16 18:37:08.594009\t收益回撤比：\t-0.82\n",
      "2025-03-16 18:37:08.594009\t策略统计指标计算完成\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "f:\\Software\\anacondaconfig\\envs\\vnpy\\lib\\site-packages\\vnpy_ctastrategy\\backtesting.py:400: FutureWarning:\n",
      "\n",
      "Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]`\n",
      "\n"
     ]
    },
    {
     "data": {
      "application/vnd.plotly.v1+json": {
       "config": {
        "plotlyServerURL": "https://plot.ly"
       },
       "data": [
        {
         "mode": "lines",
         "name": "Balance",
         "type": "scatter",
         "x": [
          "2024-01-02",
          "2024-01-03",
          "2024-01-04",
          "2024-01-05",
          "2024-01-08",
          "2024-01-09",
          "2024-01-10",
          "2024-01-11",
          "2024-01-12",
          "2024-01-15",
          "2024-01-16",
          "2024-01-17",
          "2024-01-18",
          "2024-01-19",
          "2024-01-22",
          "2024-01-23",
          "2024-01-24",
          "2024-01-25",
          "2024-01-26",
          "2024-01-29",
          "2024-01-30",
          "2024-01-31",
          "2024-02-01",
          "2024-02-02",
          "2024-02-05",
          "2024-02-06",
          "2024-02-07",
          "2024-02-08",
          "2024-02-19",
          "2024-02-20",
          "2024-02-21",
          "2024-02-22",
          "2024-02-23",
          "2024-02-26",
          "2024-02-27",
          "2024-02-28",
          "2024-02-29",
          "2024-03-01",
          "2024-03-04",
          "2024-03-05",
          "2024-03-06",
          "2024-03-07",
          "2024-03-08",
          "2024-03-11",
          "2024-03-12",
          "2024-03-13",
          "2024-03-14",
          "2024-03-15",
          "2024-03-18",
          "2024-03-19",
          "2024-03-20",
          "2024-03-21",
          "2024-03-22",
          "2024-03-25",
          "2024-03-26",
          "2024-03-27",
          "2024-03-28",
          "2024-03-29",
          "2024-04-01",
          "2024-04-02",
          "2024-04-03",
          "2024-04-08",
          "2024-04-09",
          "2024-04-10",
          "2024-04-11",
          "2024-04-12",
          "2024-04-15",
          "2024-04-16",
          "2024-04-17",
          "2024-04-18",
          "2024-04-19",
          "2024-04-22",
          "2024-04-23",
          "2024-04-24",
          "2024-04-25",
          "2024-04-26",
          "2024-04-29",
          "2024-04-30",
          "2024-05-06",
          "2024-05-07",
          "2024-05-08",
          "2024-05-09",
          "2024-05-10",
          "2024-05-13",
          "2024-05-14",
          "2024-05-15",
          "2024-05-16",
          "2024-05-17",
          "2024-05-20",
          "2024-05-21",
          "2024-05-22",
          "2024-05-23",
          "2024-05-24",
          "2024-05-27",
          "2024-05-28",
          "2024-05-29",
          "2024-05-30",
          "2024-05-31",
          "2024-06-03",
          "2024-06-04",
          "2024-06-05",
          "2024-06-06",
          "2024-06-07",
          "2024-06-11",
          "2024-06-12",
          "2024-06-13",
          "2024-06-14",
          "2024-06-17",
          "2024-06-18",
          "2024-06-19",
          "2024-06-20",
          "2024-06-21",
          "2024-06-24",
          "2024-06-25",
          "2024-06-26",
          "2024-06-27",
          "2024-06-28",
          "2024-07-01",
          "2024-07-02",
          "2024-07-03",
          "2024-07-04",
          "2024-07-05",
          "2024-07-08",
          "2024-07-09",
          "2024-07-10",
          "2024-07-11",
          "2024-07-12",
          "2024-07-15",
          "2024-07-16",
          "2024-07-17",
          "2024-07-18",
          "2024-07-19",
          "2024-07-22",
          "2024-07-23",
          "2024-07-24",
          "2024-07-25",
          "2024-07-26",
          "2024-07-29",
          "2024-07-30",
          "2024-07-31",
          "2024-08-01",
          "2024-08-02",
          "2024-08-05",
          "2024-08-06",
          "2024-08-07",
          "2024-08-08",
          "2024-08-09",
          "2024-08-12",
          "2024-08-13",
          "2024-08-14",
          "2024-08-15",
          "2024-08-16",
          "2024-08-19",
          "2024-08-20",
          "2024-08-21",
          "2024-08-22",
          "2024-08-23",
          "2024-08-26",
          "2024-08-27",
          "2024-08-28",
          "2024-08-29",
          "2024-08-30",
          "2024-09-02",
          "2024-09-03",
          "2024-09-04",
          "2024-09-05",
          "2024-09-06",
          "2024-09-09",
          "2024-09-10",
          "2024-09-11",
          "2024-09-12",
          "2024-09-13",
          "2024-09-18",
          "2024-09-19",
          "2024-09-20",
          "2024-09-23",
          "2024-09-24",
          "2024-09-25",
          "2024-09-26",
          "2024-09-27",
          "2024-09-30",
          "2024-10-08",
          "2024-10-09",
          "2024-10-10",
          "2024-10-11",
          "2024-10-14",
          "2024-10-15",
          "2024-10-16",
          "2024-10-17",
          "2024-10-18",
          "2024-10-21",
          "2024-10-22",
          "2024-10-23",
          "2024-10-24",
          "2024-10-25",
          "2024-10-28",
          "2024-10-29",
          "2024-10-30",
          "2024-10-31",
          "2024-11-01",
          "2024-11-04",
          "2024-11-05",
          "2024-11-06",
          "2024-11-07",
          "2024-11-08",
          "2024-11-11",
          "2024-11-12",
          "2024-11-13",
          "2024-11-14",
          "2024-11-15",
          "2024-11-18",
          "2024-11-19",
          "2024-11-20",
          "2024-11-21",
          "2024-11-22",
          "2024-11-25",
          "2024-11-26",
          "2024-11-27",
          "2024-11-28",
          "2024-11-29",
          "2024-12-02",
          "2024-12-03",
          "2024-12-04",
          "2024-12-05",
          "2024-12-06",
          "2024-12-09",
          "2024-12-10",
          "2024-12-11",
          "2024-12-12",
          "2024-12-13",
          "2024-12-16",
          "2024-12-17",
          "2024-12-18",
          "2024-12-19",
          "2024-12-20",
          "2024-12-23",
          "2024-12-24",
          "2024-12-25",
          "2024-12-26",
          "2024-12-27",
          "2024-12-30",
          "2024-12-31"
         ],
         "xaxis": "x",
         "y": [
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1012757.2200000001,
          1004057.2200000001,
          983057.22,
          976457.2200000001,
          970457.2200000001,
          974957.2200000001,
          968957.2200000001,
          962057.2200000001,
          985157.2200000001,
          977657.2200000001,
          966857.2200000001,
          961126.341,
          961126.341,
          960426.341,
          960826.341,
          959626.341,
          959226.341,
          959726.341,
          957326.341,
          961126.341,
          961326.341,
          962226.341,
          960626.341,
          959126.341,
          958226.341,
          959626.341,
          959726.341,
          958026.341,
          956026.3410000001,
          955026.341,
          959526.341,
          953526.341,
          954726.341,
          952626.341,
          953326.341,
          950526.341,
          946426.341,
          946426.341,
          945726.341,
          944626.341,
          943126.341,
          944126.341,
          946826.341,
          947726.341,
          948626.341,
          963026.341,
          967726.341,
          984326.341,
          990015.241,
          990015.241,
          990015.241,
          883563.8210000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001,
          895114.9810000001
         ],
         "yaxis": "y"
        },
        {
         "fill": "tozeroy",
         "fillcolor": "red",
         "mode": "lines",
         "name": "Drawdown",
         "type": "scatter",
         "x": [
          "2024-01-02",
          "2024-01-03",
          "2024-01-04",
          "2024-01-05",
          "2024-01-08",
          "2024-01-09",
          "2024-01-10",
          "2024-01-11",
          "2024-01-12",
          "2024-01-15",
          "2024-01-16",
          "2024-01-17",
          "2024-01-18",
          "2024-01-19",
          "2024-01-22",
          "2024-01-23",
          "2024-01-24",
          "2024-01-25",
          "2024-01-26",
          "2024-01-29",
          "2024-01-30",
          "2024-01-31",
          "2024-02-01",
          "2024-02-02",
          "2024-02-05",
          "2024-02-06",
          "2024-02-07",
          "2024-02-08",
          "2024-02-19",
          "2024-02-20",
          "2024-02-21",
          "2024-02-22",
          "2024-02-23",
          "2024-02-26",
          "2024-02-27",
          "2024-02-28",
          "2024-02-29",
          "2024-03-01",
          "2024-03-04",
          "2024-03-05",
          "2024-03-06",
          "2024-03-07",
          "2024-03-08",
          "2024-03-11",
          "2024-03-12",
          "2024-03-13",
          "2024-03-14",
          "2024-03-15",
          "2024-03-18",
          "2024-03-19",
          "2024-03-20",
          "2024-03-21",
          "2024-03-22",
          "2024-03-25",
          "2024-03-26",
          "2024-03-27",
          "2024-03-28",
          "2024-03-29",
          "2024-04-01",
          "2024-04-02",
          "2024-04-03",
          "2024-04-08",
          "2024-04-09",
          "2024-04-10",
          "2024-04-11",
          "2024-04-12",
          "2024-04-15",
          "2024-04-16",
          "2024-04-17",
          "2024-04-18",
          "2024-04-19",
          "2024-04-22",
          "2024-04-23",
          "2024-04-24",
          "2024-04-25",
          "2024-04-26",
          "2024-04-29",
          "2024-04-30",
          "2024-05-06",
          "2024-05-07",
          "2024-05-08",
          "2024-05-09",
          "2024-05-10",
          "2024-05-13",
          "2024-05-14",
          "2024-05-15",
          "2024-05-16",
          "2024-05-17",
          "2024-05-20",
          "2024-05-21",
          "2024-05-22",
          "2024-05-23",
          "2024-05-24",
          "2024-05-27",
          "2024-05-28",
          "2024-05-29",
          "2024-05-30",
          "2024-05-31",
          "2024-06-03",
          "2024-06-04",
          "2024-06-05",
          "2024-06-06",
          "2024-06-07",
          "2024-06-11",
          "2024-06-12",
          "2024-06-13",
          "2024-06-14",
          "2024-06-17",
          "2024-06-18",
          "2024-06-19",
          "2024-06-20",
          "2024-06-21",
          "2024-06-24",
          "2024-06-25",
          "2024-06-26",
          "2024-06-27",
          "2024-06-28",
          "2024-07-01",
          "2024-07-02",
          "2024-07-03",
          "2024-07-04",
          "2024-07-05",
          "2024-07-08",
          "2024-07-09",
          "2024-07-10",
          "2024-07-11",
          "2024-07-12",
          "2024-07-15",
          "2024-07-16",
          "2024-07-17",
          "2024-07-18",
          "2024-07-19",
          "2024-07-22",
          "2024-07-23",
          "2024-07-24",
          "2024-07-25",
          "2024-07-26",
          "2024-07-29",
          "2024-07-30",
          "2024-07-31",
          "2024-08-01",
          "2024-08-02",
          "2024-08-05",
          "2024-08-06",
          "2024-08-07",
          "2024-08-08",
          "2024-08-09",
          "2024-08-12",
          "2024-08-13",
          "2024-08-14",
          "2024-08-15",
          "2024-08-16",
          "2024-08-19",
          "2024-08-20",
          "2024-08-21",
          "2024-08-22",
          "2024-08-23",
          "2024-08-26",
          "2024-08-27",
          "2024-08-28",
          "2024-08-29",
          "2024-08-30",
          "2024-09-02",
          "2024-09-03",
          "2024-09-04",
          "2024-09-05",
          "2024-09-06",
          "2024-09-09",
          "2024-09-10",
          "2024-09-11",
          "2024-09-12",
          "2024-09-13",
          "2024-09-18",
          "2024-09-19",
          "2024-09-20",
          "2024-09-23",
          "2024-09-24",
          "2024-09-25",
          "2024-09-26",
          "2024-09-27",
          "2024-09-30",
          "2024-10-08",
          "2024-10-09",
          "2024-10-10",
          "2024-10-11",
          "2024-10-14",
          "2024-10-15",
          "2024-10-16",
          "2024-10-17",
          "2024-10-18",
          "2024-10-21",
          "2024-10-22",
          "2024-10-23",
          "2024-10-24",
          "2024-10-25",
          "2024-10-28",
          "2024-10-29",
          "2024-10-30",
          "2024-10-31",
          "2024-11-01",
          "2024-11-04",
          "2024-11-05",
          "2024-11-06",
          "2024-11-07",
          "2024-11-08",
          "2024-11-11",
          "2024-11-12",
          "2024-11-13",
          "2024-11-14",
          "2024-11-15",
          "2024-11-18",
          "2024-11-19",
          "2024-11-20",
          "2024-11-21",
          "2024-11-22",
          "2024-11-25",
          "2024-11-26",
          "2024-11-27",
          "2024-11-28",
          "2024-11-29",
          "2024-12-02",
          "2024-12-03",
          "2024-12-04",
          "2024-12-05",
          "2024-12-06",
          "2024-12-09",
          "2024-12-10",
          "2024-12-11",
          "2024-12-12",
          "2024-12-13",
          "2024-12-16",
          "2024-12-17",
          "2024-12-18",
          "2024-12-19",
          "2024-12-20",
          "2024-12-23",
          "2024-12-24",
          "2024-12-25",
          "2024-12-26",
          "2024-12-27",
          "2024-12-30",
          "2024-12-31"
         ],
         "xaxis": "x2",
         "y": [
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          -8700,
          -29700.000000000116,
          -36300,
          -42300,
          -37800,
          -43800,
          -50700,
          -27600,
          -35100,
          -45900,
          -51630.87900000007,
          -51630.87900000007,
          -52330.87900000007,
          -51930.87900000007,
          -53130.87900000007,
          -53530.87900000007,
          -53030.87900000007,
          -55430.87900000007,
          -51630.87900000007,
          -51430.87900000007,
          -50530.87900000007,
          -52130.87900000007,
          -53630.87900000007,
          -54530.87900000007,
          -53130.87900000007,
          -53030.87900000007,
          -54730.87900000007,
          -56730.87899999996,
          -57730.87900000007,
          -53230.87900000007,
          -59230.87900000007,
          -58030.87900000007,
          -60130.87900000007,
          -59430.87900000007,
          -62230.87900000007,
          -66330.87900000007,
          -66330.87900000007,
          -67030.87900000007,
          -68130.87900000007,
          -69630.87900000007,
          -68630.87900000007,
          -65930.87900000007,
          -65030.87900000007,
          -64130.87900000007,
          -49730.87900000007,
          -45030.87900000007,
          -28430.879000000074,
          -22741.97900000005,
          -22741.97900000005,
          -22741.97900000005,
          -129193.39899999998,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994,
          -117642.23899999994
         ],
         "yaxis": "y2"
        },
        {
         "name": "Daily Pnl",
         "type": "bar",
         "xaxis": "x3",
         "y": [
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          12757.220000000056,
          -8699.999999999975,
          -21000.000000000084,
          -6599.999999999939,
          -6000.0000000000055,
          4500.000000000037,
          -6000.0000000000055,
          -6900.00000000004,
          23099.99999999999,
          -7499.999999999973,
          -10800.00000000001,
          -5730.8790000000035,
          0,
          -700.0000000000117,
          400.00000000000034,
          -1200.0000000000011,
          -400.00000000000034,
          500.00000000003376,
          -2400.0000000000023,
          3799.9999999999814,
          200.0000000000224,
          899.9999999999897,
          -1600.0000000000014,
          -1500.0000000000125,
          -899.9999999999897,
          1399.999999999979,
          100.0000000000334,
          -1700.0000000000348,
          -1999.9999999999573,
          -1000.0000000000231,
          4499.999999999993,
          -6000.0000000000055,
          1200.0000000000011,
          -2099.999999999991,
          700.0000000000117,
          -2800.0000000000023,
          -4099.999999999993,
          0,
          -700.0000000000117,
          -1100.000000000012,
          -1499.999999999968,
          999.9999999999786,
          2700.0000000000136,
          899.9999999999897,
          899.9999999999897,
          14400.000000000011,
          4700.0000000000155,
          16599.999999999993,
          5688.900000000003,
          0,
          0,
          -106451.41999999995,
          11551.160000000013,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0
         ],
         "yaxis": "y3"
        },
        {
         "name": "Days",
         "nbinsx": 100,
         "type": "histogram",
         "x": [
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          12757.220000000056,
          -8699.999999999975,
          -21000.000000000084,
          -6599.999999999939,
          -6000.0000000000055,
          4500.000000000037,
          -6000.0000000000055,
          -6900.00000000004,
          23099.99999999999,
          -7499.999999999973,
          -10800.00000000001,
          -5730.8790000000035,
          0,
          -700.0000000000117,
          400.00000000000034,
          -1200.0000000000011,
          -400.00000000000034,
          500.00000000003376,
          -2400.0000000000023,
          3799.9999999999814,
          200.0000000000224,
          899.9999999999897,
          -1600.0000000000014,
          -1500.0000000000125,
          -899.9999999999897,
          1399.999999999979,
          100.0000000000334,
          -1700.0000000000348,
          -1999.9999999999573,
          -1000.0000000000231,
          4499.999999999993,
          -6000.0000000000055,
          1200.0000000000011,
          -2099.999999999991,
          700.0000000000117,
          -2800.0000000000023,
          -4099.999999999993,
          0,
          -700.0000000000117,
          -1100.000000000012,
          -1499.999999999968,
          999.9999999999786,
          2700.0000000000136,
          899.9999999999897,
          899.9999999999897,
          14400.000000000011,
          4700.0000000000155,
          16599.999999999993,
          5688.900000000003,
          0,
          0,
          -106451.41999999995,
          11551.160000000013,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0
         ],
         "xaxis": "x4",
         "yaxis": "y4"
        }
       ],
       "layout": {
        "annotations": [
         {
          "font": {
           "size": 16
          },
          "showarrow": false,
          "text": "Balance",
          "x": 0.5,
          "xanchor": "center",
          "xref": "paper",
          "y": 1,
          "yanchor": "bottom",
          "yref": "paper"
         },
         {
          "font": {
           "size": 16
          },
          "showarrow": false,
          "text": "Drawdown",
          "x": 0.5,
          "xanchor": "center",
          "xref": "paper",
          "y": 0.7350000000000001,
          "yanchor": "bottom",
          "yref": "paper"
         },
         {
          "font": {
           "size": 16
          },
          "showarrow": false,
          "text": "Daily Pnl",
          "x": 0.5,
          "xanchor": "center",
          "xref": "paper",
          "y": 0.47000000000000003,
          "yanchor": "bottom",
          "yref": "paper"
         },
         {
          "font": {
           "size": 16
          },
          "showarrow": false,
          "text": "Pnl Distribution",
          "x": 0.5,
          "xanchor": "center",
          "xref": "paper",
          "y": 0.20500000000000002,
          "yanchor": "bottom",
          "yref": "paper"
         }
        ],
        "height": 1000,
        "template": {
         "data": {
          "bar": [
           {
            "error_x": {
             "color": "#2a3f5f"
            },
            "error_y": {
             "color": "#2a3f5f"
            },
            "marker": {
             "line": {
              "color": "#E5ECF6",
              "width": 0.5
             },
             "pattern": {
              "fillmode": "overlay",
              "size": 10,
              "solidity": 0.2
             }
            },
            "type": "bar"
           }
          ],
          "barpolar": [
           {
            "marker": {
             "line": {
              "color": "#E5ECF6",
              "width": 0.5
             },
             "pattern": {
              "fillmode": "overlay",
              "size": 10,
              "solidity": 0.2
             }
            },
            "type": "barpolar"
           }
          ],
          "carpet": [
           {
            "aaxis": {
             "endlinecolor": "#2a3f5f",
             "gridcolor": "white",
             "linecolor": "white",
             "minorgridcolor": "white",
             "startlinecolor": "#2a3f5f"
            },
            "baxis": {
             "endlinecolor": "#2a3f5f",
             "gridcolor": "white",
             "linecolor": "white",
             "minorgridcolor": "white",
             "startlinecolor": "#2a3f5f"
            },
            "type": "carpet"
           }
          ],
          "choropleth": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "type": "choropleth"
           }
          ],
          "contour": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "contour"
           }
          ],
          "contourcarpet": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "type": "contourcarpet"
           }
          ],
          "heatmap": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "heatmap"
           }
          ],
          "heatmapgl": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "heatmapgl"
           }
          ],
          "histogram": [
           {
            "marker": {
             "pattern": {
              "fillmode": "overlay",
              "size": 10,
              "solidity": 0.2
             }
            },
            "type": "histogram"
           }
          ],
          "histogram2d": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "histogram2d"
           }
          ],
          "histogram2dcontour": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "histogram2dcontour"
           }
          ],
          "mesh3d": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "type": "mesh3d"
           }
          ],
          "parcoords": [
           {
            "line": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "parcoords"
           }
          ],
          "pie": [
           {
            "automargin": true,
            "type": "pie"
           }
          ],
          "scatter": [
           {
            "fillpattern": {
             "fillmode": "overlay",
             "size": 10,
             "solidity": 0.2
            },
            "type": "scatter"
           }
          ],
          "scatter3d": [
           {
            "line": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scatter3d"
           }
          ],
          "scattercarpet": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scattercarpet"
           }
          ],
          "scattergeo": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scattergeo"
           }
          ],
          "scattergl": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scattergl"
           }
          ],
          "scattermapbox": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scattermapbox"
           }
          ],
          "scatterpolar": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scatterpolar"
           }
          ],
          "scatterpolargl": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scatterpolargl"
           }
          ],
          "scatterternary": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scatterternary"
           }
          ],
          "surface": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "surface"
           }
          ],
          "table": [
           {
            "cells": {
             "fill": {
              "color": "#EBF0F8"
             },
             "line": {
              "color": "white"
             }
            },
            "header": {
             "fill": {
              "color": "#C8D4E3"
             },
             "line": {
              "color": "white"
             }
            },
            "type": "table"
           }
          ]
         },
         "layout": {
          "annotationdefaults": {
           "arrowcolor": "#2a3f5f",
           "arrowhead": 0,
           "arrowwidth": 1
          },
          "autotypenumbers": "strict",
          "coloraxis": {
           "colorbar": {
            "outlinewidth": 0,
            "ticks": ""
           }
          },
          "colorscale": {
           "diverging": [
            [
             0,
             "#8e0152"
            ],
            [
             0.1,
             "#c51b7d"
            ],
            [
             0.2,
             "#de77ae"
            ],
            [
             0.3,
             "#f1b6da"
            ],
            [
             0.4,
             "#fde0ef"
            ],
            [
             0.5,
             "#f7f7f7"
            ],
            [
             0.6,
             "#e6f5d0"
            ],
            [
             0.7,
             "#b8e186"
            ],
            [
             0.8,
             "#7fbc41"
            ],
            [
             0.9,
             "#4d9221"
            ],
            [
             1,
             "#276419"
            ]
           ],
           "sequential": [
            [
             0,
             "#0d0887"
            ],
            [
             0.1111111111111111,
             "#46039f"
            ],
            [
             0.2222222222222222,
             "#7201a8"
            ],
            [
             0.3333333333333333,
             "#9c179e"
            ],
            [
             0.4444444444444444,
             "#bd3786"
            ],
            [
             0.5555555555555556,
             "#d8576b"
            ],
            [
             0.6666666666666666,
             "#ed7953"
            ],
            [
             0.7777777777777778,
             "#fb9f3a"
            ],
            [
             0.8888888888888888,
             "#fdca26"
            ],
            [
             1,
             "#f0f921"
            ]
           ],
           "sequentialminus": [
            [
             0,
             "#0d0887"
            ],
            [
             0.1111111111111111,
             "#46039f"
            ],
            [
             0.2222222222222222,
             "#7201a8"
            ],
            [
             0.3333333333333333,
             "#9c179e"
            ],
            [
             0.4444444444444444,
             "#bd3786"
            ],
            [
             0.5555555555555556,
             "#d8576b"
            ],
            [
             0.6666666666666666,
             "#ed7953"
            ],
            [
             0.7777777777777778,
             "#fb9f3a"
            ],
            [
             0.8888888888888888,
             "#fdca26"
            ],
            [
             1,
             "#f0f921"
            ]
           ]
          },
          "colorway": [
           "#636efa",
           "#EF553B",
           "#00cc96",
           "#ab63fa",
           "#FFA15A",
           "#19d3f3",
           "#FF6692",
           "#B6E880",
           "#FF97FF",
           "#FECB52"
          ],
          "font": {
           "color": "#2a3f5f"
          },
          "geo": {
           "bgcolor": "white",
           "lakecolor": "white",
           "landcolor": "#E5ECF6",
           "showlakes": true,
           "showland": true,
           "subunitcolor": "white"
          },
          "hoverlabel": {
           "align": "left"
          },
          "hovermode": "closest",
          "mapbox": {
           "style": "light"
          },
          "paper_bgcolor": "white",
          "plot_bgcolor": "#E5ECF6",
          "polar": {
           "angularaxis": {
            "gridcolor": "white",
            "linecolor": "white",
            "ticks": ""
           },
           "bgcolor": "#E5ECF6",
           "radialaxis": {
            "gridcolor": "white",
            "linecolor": "white",
            "ticks": ""
           }
          },
          "scene": {
           "xaxis": {
            "backgroundcolor": "#E5ECF6",
            "gridcolor": "white",
            "gridwidth": 2,
            "linecolor": "white",
            "showbackground": true,
            "ticks": "",
            "zerolinecolor": "white"
           },
           "yaxis": {
            "backgroundcolor": "#E5ECF6",
            "gridcolor": "white",
            "gridwidth": 2,
            "linecolor": "white",
            "showbackground": true,
            "ticks": "",
            "zerolinecolor": "white"
           },
           "zaxis": {
            "backgroundcolor": "#E5ECF6",
            "gridcolor": "white",
            "gridwidth": 2,
            "linecolor": "white",
            "showbackground": true,
            "ticks": "",
            "zerolinecolor": "white"
           }
          },
          "shapedefaults": {
           "line": {
            "color": "#2a3f5f"
           }
          },
          "ternary": {
           "aaxis": {
            "gridcolor": "white",
            "linecolor": "white",
            "ticks": ""
           },
           "baxis": {
            "gridcolor": "white",
            "linecolor": "white",
            "ticks": ""
           },
           "bgcolor": "#E5ECF6",
           "caxis": {
            "gridcolor": "white",
            "linecolor": "white",
            "ticks": ""
           }
          },
          "title": {
           "x": 0.05
          },
          "xaxis": {
           "automargin": true,
           "gridcolor": "white",
           "linecolor": "white",
           "ticks": "",
           "title": {
            "standoff": 15
           },
           "zerolinecolor": "white",
           "zerolinewidth": 2
          },
          "yaxis": {
           "automargin": true,
           "gridcolor": "white",
           "linecolor": "white",
           "ticks": "",
           "title": {
            "standoff": 15
           },
           "zerolinecolor": "white",
           "zerolinewidth": 2
          }
         }
        },
        "width": 1000,
        "xaxis": {
         "anchor": "y",
         "domain": [
          0,
          1
         ]
        },
        "xaxis2": {
         "anchor": "y2",
         "domain": [
          0,
          1
         ]
        },
        "xaxis3": {
         "anchor": "y3",
         "domain": [
          0,
          1
         ]
        },
        "xaxis4": {
         "anchor": "y4",
         "domain": [
          0,
          1
         ]
        },
        "yaxis": {
         "anchor": "x",
         "domain": [
          0.7949999999999999,
          1
         ]
        },
        "yaxis2": {
         "anchor": "x2",
         "domain": [
          0.53,
          0.7350000000000001
         ]
        },
        "yaxis3": {
         "anchor": "x3",
         "domain": [
          0.265,
          0.47000000000000003
         ]
        },
        "yaxis4": {
         "anchor": "x4",
         "domain": [
          0,
          0.20500000000000002
         ]
        }
       }
      }
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 这是上节课的策略\n",
    "engine.add_strategy(CompositeStrategy, {})\n",
    "engine.run_backtesting()\n",
    "df = engine.calculate_result()\n",
    "engine.calculate_statistics()\n",
    "engine.show_chart()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2025-03-16 18:34:47.755109\t策略初始化完成\n",
      "2025-03-16 18:34:47.756107\t开始回放历史数据\n",
      "2025-03-16 18:34:47.756107\t回放进度：= [0%]\n",
      "2025-03-16 18:34:47.756107\t回放进度：== [10%]\n",
      "2025-03-16 18:34:47.756107\t回放进度：=== [20%]\n",
      "2025-03-16 18:34:47.757103\t回放进度：==== [30%]\n",
      "2025-03-16 18:34:47.759095\t回放进度：===== [40%]\n",
      "2025-03-16 18:34:47.761089\t回放进度：====== [50%]\n",
      "2025-03-16 18:34:47.763083\t回放进度：======= [60%]\n",
      "2025-03-16 18:34:47.766063\t回放进度：======== [70%]\n",
      "2025-03-16 18:34:47.768058\t回放进度：========= [80%]\n",
      "2025-03-16 18:34:47.770052\t回放进度：========== [90%]\n",
      "2025-03-16 18:34:47.770052\t回放进度：=========== [100%]\n",
      "2025-03-16 18:34:47.770052\t历史数据回放结束\n",
      "2025-03-16 18:34:47.770052\t开始计算逐日盯市盈亏\n",
      "2025-03-16 18:34:47.772055\t逐日盯市盈亏计算完成\n",
      "2025-03-16 18:34:47.772055\t开始计算策略统计指标\n",
      "2025-03-16 18:34:47.776112\t------------------------------\n",
      "2025-03-16 18:34:47.776112\t首个交易日：\t2024-01-02\n",
      "2025-03-16 18:34:47.776112\t最后交易日：\t2024-12-31\n",
      "2025-03-16 18:34:47.776112\t总交易日：\t242\n",
      "2025-03-16 18:34:47.776112\t盈利交易日：\t4\n",
      "2025-03-16 18:34:47.776112\t亏损交易日：\t10\n",
      "2025-03-16 18:34:47.776112\t起始资金：\t1,000,000.00\n",
      "2025-03-16 18:34:47.776112\t结束资金：\t963,853.95\n",
      "2025-03-16 18:34:47.776112\t总收益率：\t-3.61%\n",
      "2025-03-16 18:34:47.776112\t年化收益：\t-3.58%\n",
      "2025-03-16 18:34:47.776112\t最大回撤: \t-43,823.15\n",
      "2025-03-16 18:34:47.776112\t百分比最大回撤: -4.37%\n",
      "2025-03-16 18:34:47.776112\t最大回撤天数: \t82\n",
      "2025-03-16 18:34:47.776112\t总盈亏：\t-36,146.05\n",
      "2025-03-16 18:34:47.776112\t总手续费：\t46.05\n",
      "2025-03-16 18:34:47.776112\t总滑点：\t1,200.00\n",
      "2025-03-16 18:34:47.776112\t总成交金额：\t1,535,100.00\n",
      "2025-03-16 18:34:47.776112\t总成交笔数：\t4\n",
      "2025-03-16 18:34:47.776112\t日均盈亏：\t-149.36\n",
      "2025-03-16 18:34:47.776112\t日均手续费：\t0.19\n",
      "2025-03-16 18:34:47.776112\t日均滑点：\t4.96\n",
      "2025-03-16 18:34:47.776112\t日均成交金额：\t6,343.39\n",
      "2025-03-16 18:34:47.776112\t日均成交笔数：\t0.01652892561983471\n",
      "2025-03-16 18:34:47.776112\t日均收益率：\t-0.02%\n",
      "2025-03-16 18:34:47.776112\t收益标准差：\t0.20%\n",
      "2025-03-16 18:34:47.776112\tSharpe Ratio：\t-1.20\n",
      "2025-03-16 18:34:47.776112\tEWM Sharpe：\t-1.27\n",
      "2025-03-16 18:34:47.776112\t收益回撤比：\t-0.83\n",
      "2025-03-16 18:34:47.776112\t策略统计指标计算完成\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "f:\\Software\\anacondaconfig\\envs\\vnpy\\lib\\site-packages\\vnpy_ctastrategy\\backtesting.py:400: FutureWarning:\n",
      "\n",
      "Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]`\n",
      "\n"
     ]
    },
    {
     "data": {
      "application/vnd.plotly.v1+json": {
       "config": {
        "plotlyServerURL": "https://plot.ly"
       },
       "data": [
        {
         "mode": "lines",
         "name": "Balance",
         "type": "scatter",
         "x": [
          "2024-01-02",
          "2024-01-03",
          "2024-01-04",
          "2024-01-05",
          "2024-01-08",
          "2024-01-09",
          "2024-01-10",
          "2024-01-11",
          "2024-01-12",
          "2024-01-15",
          "2024-01-16",
          "2024-01-17",
          "2024-01-18",
          "2024-01-19",
          "2024-01-22",
          "2024-01-23",
          "2024-01-24",
          "2024-01-25",
          "2024-01-26",
          "2024-01-29",
          "2024-01-30",
          "2024-01-31",
          "2024-02-01",
          "2024-02-02",
          "2024-02-05",
          "2024-02-06",
          "2024-02-07",
          "2024-02-08",
          "2024-02-19",
          "2024-02-20",
          "2024-02-21",
          "2024-02-22",
          "2024-02-23",
          "2024-02-26",
          "2024-02-27",
          "2024-02-28",
          "2024-02-29",
          "2024-03-01",
          "2024-03-04",
          "2024-03-05",
          "2024-03-06",
          "2024-03-07",
          "2024-03-08",
          "2024-03-11",
          "2024-03-12",
          "2024-03-13",
          "2024-03-14",
          "2024-03-15",
          "2024-03-18",
          "2024-03-19",
          "2024-03-20",
          "2024-03-21",
          "2024-03-22",
          "2024-03-25",
          "2024-03-26",
          "2024-03-27",
          "2024-03-28",
          "2024-03-29",
          "2024-04-01",
          "2024-04-02",
          "2024-04-03",
          "2024-04-08",
          "2024-04-09",
          "2024-04-10",
          "2024-04-11",
          "2024-04-12",
          "2024-04-15",
          "2024-04-16",
          "2024-04-17",
          "2024-04-18",
          "2024-04-19",
          "2024-04-22",
          "2024-04-23",
          "2024-04-24",
          "2024-04-25",
          "2024-04-26",
          "2024-04-29",
          "2024-04-30",
          "2024-05-06",
          "2024-05-07",
          "2024-05-08",
          "2024-05-09",
          "2024-05-10",
          "2024-05-13",
          "2024-05-14",
          "2024-05-15",
          "2024-05-16",
          "2024-05-17",
          "2024-05-20",
          "2024-05-21",
          "2024-05-22",
          "2024-05-23",
          "2024-05-24",
          "2024-05-27",
          "2024-05-28",
          "2024-05-29",
          "2024-05-30",
          "2024-05-31",
          "2024-06-03",
          "2024-06-04",
          "2024-06-05",
          "2024-06-06",
          "2024-06-07",
          "2024-06-11",
          "2024-06-12",
          "2024-06-13",
          "2024-06-14",
          "2024-06-17",
          "2024-06-18",
          "2024-06-19",
          "2024-06-20",
          "2024-06-21",
          "2024-06-24",
          "2024-06-25",
          "2024-06-26",
          "2024-06-27",
          "2024-06-28",
          "2024-07-01",
          "2024-07-02",
          "2024-07-03",
          "2024-07-04",
          "2024-07-05",
          "2024-07-08",
          "2024-07-09",
          "2024-07-10",
          "2024-07-11",
          "2024-07-12",
          "2024-07-15",
          "2024-07-16",
          "2024-07-17",
          "2024-07-18",
          "2024-07-19",
          "2024-07-22",
          "2024-07-23",
          "2024-07-24",
          "2024-07-25",
          "2024-07-26",
          "2024-07-29",
          "2024-07-30",
          "2024-07-31",
          "2024-08-01",
          "2024-08-02",
          "2024-08-05",
          "2024-08-06",
          "2024-08-07",
          "2024-08-08",
          "2024-08-09",
          "2024-08-12",
          "2024-08-13",
          "2024-08-14",
          "2024-08-15",
          "2024-08-16",
          "2024-08-19",
          "2024-08-20",
          "2024-08-21",
          "2024-08-22",
          "2024-08-23",
          "2024-08-26",
          "2024-08-27",
          "2024-08-28",
          "2024-08-29",
          "2024-08-30",
          "2024-09-02",
          "2024-09-03",
          "2024-09-04",
          "2024-09-05",
          "2024-09-06",
          "2024-09-09",
          "2024-09-10",
          "2024-09-11",
          "2024-09-12",
          "2024-09-13",
          "2024-09-18",
          "2024-09-19",
          "2024-09-20",
          "2024-09-23",
          "2024-09-24",
          "2024-09-25",
          "2024-09-26",
          "2024-09-27",
          "2024-09-30",
          "2024-10-08",
          "2024-10-09",
          "2024-10-10",
          "2024-10-11",
          "2024-10-14",
          "2024-10-15",
          "2024-10-16",
          "2024-10-17",
          "2024-10-18",
          "2024-10-21",
          "2024-10-22",
          "2024-10-23",
          "2024-10-24",
          "2024-10-25",
          "2024-10-28",
          "2024-10-29",
          "2024-10-30",
          "2024-10-31",
          "2024-11-01",
          "2024-11-04",
          "2024-11-05",
          "2024-11-06",
          "2024-11-07",
          "2024-11-08",
          "2024-11-11",
          "2024-11-12",
          "2024-11-13",
          "2024-11-14",
          "2024-11-15",
          "2024-11-18",
          "2024-11-19",
          "2024-11-20",
          "2024-11-21",
          "2024-11-22",
          "2024-11-25",
          "2024-11-26",
          "2024-11-27",
          "2024-11-28",
          "2024-11-29",
          "2024-12-02",
          "2024-12-03",
          "2024-12-04",
          "2024-12-05",
          "2024-12-06",
          "2024-12-09",
          "2024-12-10",
          "2024-12-11",
          "2024-12-12",
          "2024-12-13",
          "2024-12-16",
          "2024-12-17",
          "2024-12-18",
          "2024-12-19",
          "2024-12-20",
          "2024-12-23",
          "2024-12-24",
          "2024-12-25",
          "2024-12-26",
          "2024-12-27",
          "2024-12-30",
          "2024-12-31"
         ],
         "xaxis": "x",
         "y": [
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1003189.305,
          1000289.305,
          993289.305,
          991089.305,
          989089.305,
          990589.305,
          988589.305,
          986289.305,
          993989.305,
          991489.305,
          987889.305,
          985979.012,
          985979.012,
          985979.012,
          985979.012,
          985979.012,
          985979.012,
          985979.012,
          985979.012,
          985979.012,
          985979.012,
          985979.012,
          985979.012,
          985979.012,
          985979.012,
          985979.012,
          985979.012,
          985979.012,
          985979.012,
          985979.012,
          985979.012,
          985979.012,
          985979.012,
          985979.012,
          985979.012,
          985979.012,
          985979.012,
          985979.012,
          985979.012,
          985979.012,
          985979.012,
          985979.012,
          985979.012,
          985979.012,
          985979.012,
          985979.012,
          985979.012,
          985979.012,
          985979.012,
          985979.012,
          985979.012,
          959366.157,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947,
          963853.947
         ],
         "yaxis": "y"
        },
        {
         "fill": "tozeroy",
         "fillcolor": "red",
         "mode": "lines",
         "name": "Drawdown",
         "type": "scatter",
         "x": [
          "2024-01-02",
          "2024-01-03",
          "2024-01-04",
          "2024-01-05",
          "2024-01-08",
          "2024-01-09",
          "2024-01-10",
          "2024-01-11",
          "2024-01-12",
          "2024-01-15",
          "2024-01-16",
          "2024-01-17",
          "2024-01-18",
          "2024-01-19",
          "2024-01-22",
          "2024-01-23",
          "2024-01-24",
          "2024-01-25",
          "2024-01-26",
          "2024-01-29",
          "2024-01-30",
          "2024-01-31",
          "2024-02-01",
          "2024-02-02",
          "2024-02-05",
          "2024-02-06",
          "2024-02-07",
          "2024-02-08",
          "2024-02-19",
          "2024-02-20",
          "2024-02-21",
          "2024-02-22",
          "2024-02-23",
          "2024-02-26",
          "2024-02-27",
          "2024-02-28",
          "2024-02-29",
          "2024-03-01",
          "2024-03-04",
          "2024-03-05",
          "2024-03-06",
          "2024-03-07",
          "2024-03-08",
          "2024-03-11",
          "2024-03-12",
          "2024-03-13",
          "2024-03-14",
          "2024-03-15",
          "2024-03-18",
          "2024-03-19",
          "2024-03-20",
          "2024-03-21",
          "2024-03-22",
          "2024-03-25",
          "2024-03-26",
          "2024-03-27",
          "2024-03-28",
          "2024-03-29",
          "2024-04-01",
          "2024-04-02",
          "2024-04-03",
          "2024-04-08",
          "2024-04-09",
          "2024-04-10",
          "2024-04-11",
          "2024-04-12",
          "2024-04-15",
          "2024-04-16",
          "2024-04-17",
          "2024-04-18",
          "2024-04-19",
          "2024-04-22",
          "2024-04-23",
          "2024-04-24",
          "2024-04-25",
          "2024-04-26",
          "2024-04-29",
          "2024-04-30",
          "2024-05-06",
          "2024-05-07",
          "2024-05-08",
          "2024-05-09",
          "2024-05-10",
          "2024-05-13",
          "2024-05-14",
          "2024-05-15",
          "2024-05-16",
          "2024-05-17",
          "2024-05-20",
          "2024-05-21",
          "2024-05-22",
          "2024-05-23",
          "2024-05-24",
          "2024-05-27",
          "2024-05-28",
          "2024-05-29",
          "2024-05-30",
          "2024-05-31",
          "2024-06-03",
          "2024-06-04",
          "2024-06-05",
          "2024-06-06",
          "2024-06-07",
          "2024-06-11",
          "2024-06-12",
          "2024-06-13",
          "2024-06-14",
          "2024-06-17",
          "2024-06-18",
          "2024-06-19",
          "2024-06-20",
          "2024-06-21",
          "2024-06-24",
          "2024-06-25",
          "2024-06-26",
          "2024-06-27",
          "2024-06-28",
          "2024-07-01",
          "2024-07-02",
          "2024-07-03",
          "2024-07-04",
          "2024-07-05",
          "2024-07-08",
          "2024-07-09",
          "2024-07-10",
          "2024-07-11",
          "2024-07-12",
          "2024-07-15",
          "2024-07-16",
          "2024-07-17",
          "2024-07-18",
          "2024-07-19",
          "2024-07-22",
          "2024-07-23",
          "2024-07-24",
          "2024-07-25",
          "2024-07-26",
          "2024-07-29",
          "2024-07-30",
          "2024-07-31",
          "2024-08-01",
          "2024-08-02",
          "2024-08-05",
          "2024-08-06",
          "2024-08-07",
          "2024-08-08",
          "2024-08-09",
          "2024-08-12",
          "2024-08-13",
          "2024-08-14",
          "2024-08-15",
          "2024-08-16",
          "2024-08-19",
          "2024-08-20",
          "2024-08-21",
          "2024-08-22",
          "2024-08-23",
          "2024-08-26",
          "2024-08-27",
          "2024-08-28",
          "2024-08-29",
          "2024-08-30",
          "2024-09-02",
          "2024-09-03",
          "2024-09-04",
          "2024-09-05",
          "2024-09-06",
          "2024-09-09",
          "2024-09-10",
          "2024-09-11",
          "2024-09-12",
          "2024-09-13",
          "2024-09-18",
          "2024-09-19",
          "2024-09-20",
          "2024-09-23",
          "2024-09-24",
          "2024-09-25",
          "2024-09-26",
          "2024-09-27",
          "2024-09-30",
          "2024-10-08",
          "2024-10-09",
          "2024-10-10",
          "2024-10-11",
          "2024-10-14",
          "2024-10-15",
          "2024-10-16",
          "2024-10-17",
          "2024-10-18",
          "2024-10-21",
          "2024-10-22",
          "2024-10-23",
          "2024-10-24",
          "2024-10-25",
          "2024-10-28",
          "2024-10-29",
          "2024-10-30",
          "2024-10-31",
          "2024-11-01",
          "2024-11-04",
          "2024-11-05",
          "2024-11-06",
          "2024-11-07",
          "2024-11-08",
          "2024-11-11",
          "2024-11-12",
          "2024-11-13",
          "2024-11-14",
          "2024-11-15",
          "2024-11-18",
          "2024-11-19",
          "2024-11-20",
          "2024-11-21",
          "2024-11-22",
          "2024-11-25",
          "2024-11-26",
          "2024-11-27",
          "2024-11-28",
          "2024-11-29",
          "2024-12-02",
          "2024-12-03",
          "2024-12-04",
          "2024-12-05",
          "2024-12-06",
          "2024-12-09",
          "2024-12-10",
          "2024-12-11",
          "2024-12-12",
          "2024-12-13",
          "2024-12-16",
          "2024-12-17",
          "2024-12-18",
          "2024-12-19",
          "2024-12-20",
          "2024-12-23",
          "2024-12-24",
          "2024-12-25",
          "2024-12-26",
          "2024-12-27",
          "2024-12-30",
          "2024-12-31"
         ],
         "xaxis": "x2",
         "y": [
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          -2900,
          -9900,
          -12100,
          -14100,
          -12600,
          -14600,
          -16900,
          -9200,
          -11700,
          -15300,
          -17210.293000000063,
          -17210.293000000063,
          -17210.293000000063,
          -17210.293000000063,
          -17210.293000000063,
          -17210.293000000063,
          -17210.293000000063,
          -17210.293000000063,
          -17210.293000000063,
          -17210.293000000063,
          -17210.293000000063,
          -17210.293000000063,
          -17210.293000000063,
          -17210.293000000063,
          -17210.293000000063,
          -17210.293000000063,
          -17210.293000000063,
          -17210.293000000063,
          -17210.293000000063,
          -17210.293000000063,
          -17210.293000000063,
          -17210.293000000063,
          -17210.293000000063,
          -17210.293000000063,
          -17210.293000000063,
          -17210.293000000063,
          -17210.293000000063,
          -17210.293000000063,
          -17210.293000000063,
          -17210.293000000063,
          -17210.293000000063,
          -17210.293000000063,
          -17210.293000000063,
          -17210.293000000063,
          -17210.293000000063,
          -17210.293000000063,
          -17210.293000000063,
          -17210.293000000063,
          -17210.293000000063,
          -17210.293000000063,
          -43823.148000000045,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001,
          -39335.35800000001
         ],
         "yaxis": "y2"
        },
        {
         "name": "Daily Pnl",
         "type": "bar",
         "xaxis": "x3",
         "y": [
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          3189.305000000014,
          -2899.9999999999914,
          -7000.000000000028,
          -2199.9999999999795,
          -2000.0000000000018,
          1500.0000000000125,
          -2000.0000000000018,
          -2300.000000000013,
          7699.999999999995,
          -2499.999999999991,
          -3600.0000000000027,
          -1910.2930000000008,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          -26612.85499999999,
          4487.790000000004,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0
         ],
         "yaxis": "y3"
        },
        {
         "name": "Days",
         "nbinsx": 100,
         "type": "histogram",
         "x": [
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          3189.305000000014,
          -2899.9999999999914,
          -7000.000000000028,
          -2199.9999999999795,
          -2000.0000000000018,
          1500.0000000000125,
          -2000.0000000000018,
          -2300.000000000013,
          7699.999999999995,
          -2499.999999999991,
          -3600.0000000000027,
          -1910.2930000000008,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          -26612.85499999999,
          4487.790000000004,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0
         ],
         "xaxis": "x4",
         "yaxis": "y4"
        }
       ],
       "layout": {
        "annotations": [
         {
          "font": {
           "size": 16
          },
          "showarrow": false,
          "text": "Balance",
          "x": 0.5,
          "xanchor": "center",
          "xref": "paper",
          "y": 1,
          "yanchor": "bottom",
          "yref": "paper"
         },
         {
          "font": {
           "size": 16
          },
          "showarrow": false,
          "text": "Drawdown",
          "x": 0.5,
          "xanchor": "center",
          "xref": "paper",
          "y": 0.7350000000000001,
          "yanchor": "bottom",
          "yref": "paper"
         },
         {
          "font": {
           "size": 16
          },
          "showarrow": false,
          "text": "Daily Pnl",
          "x": 0.5,
          "xanchor": "center",
          "xref": "paper",
          "y": 0.47000000000000003,
          "yanchor": "bottom",
          "yref": "paper"
         },
         {
          "font": {
           "size": 16
          },
          "showarrow": false,
          "text": "Pnl Distribution",
          "x": 0.5,
          "xanchor": "center",
          "xref": "paper",
          "y": 0.20500000000000002,
          "yanchor": "bottom",
          "yref": "paper"
         }
        ],
        "height": 1000,
        "template": {
         "data": {
          "bar": [
           {
            "error_x": {
             "color": "#2a3f5f"
            },
            "error_y": {
             "color": "#2a3f5f"
            },
            "marker": {
             "line": {
              "color": "#E5ECF6",
              "width": 0.5
             },
             "pattern": {
              "fillmode": "overlay",
              "size": 10,
              "solidity": 0.2
             }
            },
            "type": "bar"
           }
          ],
          "barpolar": [
           {
            "marker": {
             "line": {
              "color": "#E5ECF6",
              "width": 0.5
             },
             "pattern": {
              "fillmode": "overlay",
              "size": 10,
              "solidity": 0.2
             }
            },
            "type": "barpolar"
           }
          ],
          "carpet": [
           {
            "aaxis": {
             "endlinecolor": "#2a3f5f",
             "gridcolor": "white",
             "linecolor": "white",
             "minorgridcolor": "white",
             "startlinecolor": "#2a3f5f"
            },
            "baxis": {
             "endlinecolor": "#2a3f5f",
             "gridcolor": "white",
             "linecolor": "white",
             "minorgridcolor": "white",
             "startlinecolor": "#2a3f5f"
            },
            "type": "carpet"
           }
          ],
          "choropleth": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "type": "choropleth"
           }
          ],
          "contour": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "contour"
           }
          ],
          "contourcarpet": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "type": "contourcarpet"
           }
          ],
          "heatmap": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "heatmap"
           }
          ],
          "heatmapgl": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "heatmapgl"
           }
          ],
          "histogram": [
           {
            "marker": {
             "pattern": {
              "fillmode": "overlay",
              "size": 10,
              "solidity": 0.2
             }
            },
            "type": "histogram"
           }
          ],
          "histogram2d": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "histogram2d"
           }
          ],
          "histogram2dcontour": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "histogram2dcontour"
           }
          ],
          "mesh3d": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "type": "mesh3d"
           }
          ],
          "parcoords": [
           {
            "line": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "parcoords"
           }
          ],
          "pie": [
           {
            "automargin": true,
            "type": "pie"
           }
          ],
          "scatter": [
           {
            "fillpattern": {
             "fillmode": "overlay",
             "size": 10,
             "solidity": 0.2
            },
            "type": "scatter"
           }
          ],
          "scatter3d": [
           {
            "line": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scatter3d"
           }
          ],
          "scattercarpet": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scattercarpet"
           }
          ],
          "scattergeo": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scattergeo"
           }
          ],
          "scattergl": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scattergl"
           }
          ],
          "scattermapbox": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scattermapbox"
           }
          ],
          "scatterpolar": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scatterpolar"
           }
          ],
          "scatterpolargl": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scatterpolargl"
           }
          ],
          "scatterternary": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scatterternary"
           }
          ],
          "surface": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "surface"
           }
          ],
          "table": [
           {
            "cells": {
             "fill": {
              "color": "#EBF0F8"
             },
             "line": {
              "color": "white"
             }
            },
            "header": {
             "fill": {
              "color": "#C8D4E3"
             },
             "line": {
              "color": "white"
             }
            },
            "type": "table"
           }
          ]
         },
         "layout": {
          "annotationdefaults": {
           "arrowcolor": "#2a3f5f",
           "arrowhead": 0,
           "arrowwidth": 1
          },
          "autotypenumbers": "strict",
          "coloraxis": {
           "colorbar": {
            "outlinewidth": 0,
            "ticks": ""
           }
          },
          "colorscale": {
           "diverging": [
            [
             0,
             "#8e0152"
            ],
            [
             0.1,
             "#c51b7d"
            ],
            [
             0.2,
             "#de77ae"
            ],
            [
             0.3,
             "#f1b6da"
            ],
            [
             0.4,
             "#fde0ef"
            ],
            [
             0.5,
             "#f7f7f7"
            ],
            [
             0.6,
             "#e6f5d0"
            ],
            [
             0.7,
             "#b8e186"
            ],
            [
             0.8,
             "#7fbc41"
            ],
            [
             0.9,
             "#4d9221"
            ],
            [
             1,
             "#276419"
            ]
           ],
           "sequential": [
            [
             0,
             "#0d0887"
            ],
            [
             0.1111111111111111,
             "#46039f"
            ],
            [
             0.2222222222222222,
             "#7201a8"
            ],
            [
             0.3333333333333333,
             "#9c179e"
            ],
            [
             0.4444444444444444,
             "#bd3786"
            ],
            [
             0.5555555555555556,
             "#d8576b"
            ],
            [
             0.6666666666666666,
             "#ed7953"
            ],
            [
             0.7777777777777778,
             "#fb9f3a"
            ],
            [
             0.8888888888888888,
             "#fdca26"
            ],
            [
             1,
             "#f0f921"
            ]
           ],
           "sequentialminus": [
            [
             0,
             "#0d0887"
            ],
            [
             0.1111111111111111,
             "#46039f"
            ],
            [
             0.2222222222222222,
             "#7201a8"
            ],
            [
             0.3333333333333333,
             "#9c179e"
            ],
            [
             0.4444444444444444,
             "#bd3786"
            ],
            [
             0.5555555555555556,
             "#d8576b"
            ],
            [
             0.6666666666666666,
             "#ed7953"
            ],
            [
             0.7777777777777778,
             "#fb9f3a"
            ],
            [
             0.8888888888888888,
             "#fdca26"
            ],
            [
             1,
             "#f0f921"
            ]
           ]
          },
          "colorway": [
           "#636efa",
           "#EF553B",
           "#00cc96",
           "#ab63fa",
           "#FFA15A",
           "#19d3f3",
           "#FF6692",
           "#B6E880",
           "#FF97FF",
           "#FECB52"
          ],
          "font": {
           "color": "#2a3f5f"
          },
          "geo": {
           "bgcolor": "white",
           "lakecolor": "white",
           "landcolor": "#E5ECF6",
           "showlakes": true,
           "showland": true,
           "subunitcolor": "white"
          },
          "hoverlabel": {
           "align": "left"
          },
          "hovermode": "closest",
          "mapbox": {
           "style": "light"
          },
          "paper_bgcolor": "white",
          "plot_bgcolor": "#E5ECF6",
          "polar": {
           "angularaxis": {
            "gridcolor": "white",
            "linecolor": "white",
            "ticks": ""
           },
           "bgcolor": "#E5ECF6",
           "radialaxis": {
            "gridcolor": "white",
            "linecolor": "white",
            "ticks": ""
           }
          },
          "scene": {
           "xaxis": {
            "backgroundcolor": "#E5ECF6",
            "gridcolor": "white",
            "gridwidth": 2,
            "linecolor": "white",
            "showbackground": true,
            "ticks": "",
            "zerolinecolor": "white"
           },
           "yaxis": {
            "backgroundcolor": "#E5ECF6",
            "gridcolor": "white",
            "gridwidth": 2,
            "linecolor": "white",
            "showbackground": true,
            "ticks": "",
            "zerolinecolor": "white"
           },
           "zaxis": {
            "backgroundcolor": "#E5ECF6",
            "gridcolor": "white",
            "gridwidth": 2,
            "linecolor": "white",
            "showbackground": true,
            "ticks": "",
            "zerolinecolor": "white"
           }
          },
          "shapedefaults": {
           "line": {
            "color": "#2a3f5f"
           }
          },
          "ternary": {
           "aaxis": {
            "gridcolor": "white",
            "linecolor": "white",
            "ticks": ""
           },
           "baxis": {
            "gridcolor": "white",
            "linecolor": "white",
            "ticks": ""
           },
           "bgcolor": "#E5ECF6",
           "caxis": {
            "gridcolor": "white",
            "linecolor": "white",
            "ticks": ""
           }
          },
          "title": {
           "x": 0.05
          },
          "xaxis": {
           "automargin": true,
           "gridcolor": "white",
           "linecolor": "white",
           "ticks": "",
           "title": {
            "standoff": 15
           },
           "zerolinecolor": "white",
           "zerolinewidth": 2
          },
          "yaxis": {
           "automargin": true,
           "gridcolor": "white",
           "linecolor": "white",
           "ticks": "",
           "title": {
            "standoff": 15
           },
           "zerolinecolor": "white",
           "zerolinewidth": 2
          }
         }
        },
        "width": 1000,
        "xaxis": {
         "anchor": "y",
         "domain": [
          0,
          1
         ]
        },
        "xaxis2": {
         "anchor": "y2",
         "domain": [
          0,
          1
         ]
        },
        "xaxis3": {
         "anchor": "y3",
         "domain": [
          0,
          1
         ]
        },
        "xaxis4": {
         "anchor": "y4",
         "domain": [
          0,
          1
         ]
        },
        "yaxis": {
         "anchor": "x",
         "domain": [
          0.7949999999999999,
          1
         ]
        },
        "yaxis2": {
         "anchor": "x2",
         "domain": [
          0.53,
          0.7350000000000001
         ]
        },
        "yaxis3": {
         "anchor": "x3",
         "domain": [
          0.265,
          0.47000000000000003
         ]
        },
        "yaxis4": {
         "anchor": "x4",
         "domain": [
          0,
          0.20500000000000002
         ]
        }
       }
      }
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 这是在原来的策略的基础上经济环境因素后的策略\n",
    "engine.add_strategy(MacroMarketStrategy, {})\n",
    "engine.run_backtesting()\n",
    "df = engine.calculate_result()\n",
    "engine.calculate_statistics()\n",
    "engine.show_chart()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 对比分析\n",
    "---\n",
    "\n",
    "### **1. 盈利情况**\n",
    "• **仅技术指标策略**：\n",
    "  • 盈利交易日：22天\n",
    "  • 亏损交易日：27天\n",
    "  • 结束资金：895,114.98元\n",
    "• **加入宏观经济因素策略**：\n",
    "  • 盈利交易日：4天\n",
    "  • 亏损交易日：10天\n",
    "  • 结束资金：963,853.95元\n",
    "\n",
    "**分析**：\n",
    "• 加入宏观经济因素后，盈利交易日大幅减少（从22天减少到4天），亏损交易日也减少了（从27天减少到10天），但整体收益却略有上升（从895,114.98元增加到963,853.95元）。\n",
    "• 这表明加入宏观经济因素后，策略的交易频率显著降低，可能是过滤掉了一些交易机会，但同时也减少了亏损的可能性。\n",
    "\n",
    "---\n",
    "\n",
    "### **2. 收益表现**\n",
    "• **仅技术指标策略**的结束资金为895,114.98元，而**加入宏观经济因素策略**的结束资金为963,853.95元。\n",
    "• 虽然加入宏观经济因素后收益有所上升，但这种提升幅度相对较小，可能并不显著。\n",
    "\n",
    "---\n",
    "\n",
    "### **3. 风险指标**\n",
    "• **Sharpe Ratio（夏普比率）**：\n",
    "  • 仅技术指标策略：-0.89（优化后：-0.94）\n",
    "  • 加入宏观经济因素策略：-1.20（优化后：-1.27）\n",
    "• **收益回撤比**：\n",
    "  • 仅技术指标策略：-0.8\n",
    "  • 加入宏观经济因素策略：-0.83\n",
    "\n",
    "**分析**：\n",
    "• Sharpe Ratio和收益回撤比均显著下降，表明加入宏观经济因素后，策略的风险调整后收益变得更差。\n",
    "• 收益回撤比也进一步下降，说明策略在控制回撤方面没有显著改善，甚至可能有所恶化。\n",
    "\n",
    "---\n",
    "\n",
    "### **4. 策略逻辑的可能问题**\n",
    "• **宏观经济因素的引入可能增加了策略的复杂性**：\n",
    "  • CPI数据是宏观经济的重要指标，但其对市场的传导机制可能并不直接，尤其是在短期交易中。如果CPI数据的信号与技术指标信号不一致，可能导致策略频繁过滤掉交易机会，甚至产生误导。\n",
    "• **信号过滤过于严格**：\n",
    "  • 加入宏观经济因素后，盈利交易日大幅减少，可能是策略对交易信号的要求变得过于严格，导致错过了一些潜在的盈利机会。\n",
    "• **CPI数据的滞后性**：\n",
    "  • CPI数据通常是月度或季度发布的，具有一定的滞后性。在高频交易中，使用滞后数据可能导致信号失效。\n",
    "\n",
    "---\n",
    "\n",
    "### **5. 改进建议**\n",
    "1. **重新评估宏观经济因素的作用**：\n",
    "   • 检查CPI数据是否对策略有真正的增益。可以通过分组回测（如高CPI和低CPI环境下的策略表现）来验证其有效性。\n",
    "   • 如果CPI数据的信号与技术指标信号的契合度较低，考虑剔除或替换为其他更相关的宏观经济指标。\n",
    "\n",
    "2. **优化信号权重**：\n",
    "   • 如果决定保留CPI数据，可以尝试调整技术指标和CPI数据的权重，找到一个平衡点，既能提高收益，又能控制风险。\n",
    "\n",
    "3. **引入动态过滤机制**：\n",
    "   • 不要完全依赖CPI数据过滤交易信号，而是将其作为辅助指标。例如，只有在CPI数据支持技术指标信号时才进行交易。\n",
    "\n",
    "4. **降低滞后性影响**：\n",
    "   • 如果使用CPI数据，尽量选择更高频率的指标（如月度CPI的预测值）或结合实时数据（如通胀预期）来减少滞后性。\n",
    "\n",
    "---\n",
    "\n",
    "### **6. 总结**\n",
    "• 加入CPI数据后，策略的交易频率显著降低，收益略有提升，但风险调整后收益（Sharpe Ratio和收益回撤比）显著恶化。\n",
    "• 这表明CPI数据可能并未为策略带来真正的增益，反而可能引入了更多的复杂性。\n",
    "• 建议重新评估CPI数据的有效性，并尝试优化信号权重或过滤机制，避免过度依赖单一宏观经济指标。\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "vnpy",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
